package Algorithm.Othes;

public class Leetcode400 {
    class Solution {
        public int findNthDigit(int n) {
            //位数的规律为 1*9, 2*90,3*900
            //先是找到 n 是几位数，然后再找是具体哪个数
            long i = 1;
            long j = 9;
            long base = 0;
            long m = (long) n;
            while(m>(i*j)){
                m = m - i*j;
                i = i + 1;
                j = j * 10;
                base = base * 10 + 9;
            }

            long k = m/i;
            long del = m%i;
            long num = base + k;
            if(del>0){
                num = base + k + 1;
            }else{
                del = i;
            }

            return (String.valueOf(num).charAt((int)del-1)-'0');
        }
    }
}
